package anuncios;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import SQL.Conect;

import usuaris.Empresa;

public class TablonAnuncios {
	
	Conect conector = new Conect();
	Connection con= conector.conect(); 
	List <Oferta> ofertas = new ArrayList <Oferta>();

	public TablonAnuncios(){
	}
	
	public List<Oferta> getOfertas() {
		return ofertas;
	}
	
	public void demandas(){
		Statement st;
		ResultSet rs;
		try {
			st = con.createStatement();
			rs = st.executeQuery("select * from oferta where em_alum=1 AND activa=0");
			while (rs.next()) {				
				ofertas.add( new Oferta ( rs.getInt("id"),rs.getInt("activa"), rs.getInt("em_alum"),rs.getString("titol"), rs.getString("descripcio"),
						rs.getString("identificador"),rs.getString("tipus_cicle") ) );
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	
	public void ofertas(){
		Statement st;
		ResultSet rs;
		try {
			st = con.createStatement();
			rs = st.executeQuery("select * from oferta where em_alum=0 AND activa=0");
			while (rs.next()) {
				ofertas.add( new Oferta ( rs.getInt("id"),rs.getInt("activa"), rs.getInt("em_alum"),rs.getString("titol"), rs.getString("descripcio"),
						rs.getString("identificador"),rs.getString("tipus_cicle") ) );
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}
